import 'package:flutter/material.dart';
import 'package:flutter_jd/pages/goods/comment/controller.dart';
import 'package:flutter_jd/ui/widgets/preview/picture_view.dart';
import 'package:flutter_jd/ui/widgets/refresh/pull_refresh.dart';
import 'package:flutter_jd/ui/widgets/body/top_bar.dart';
import 'package:get/get_state_manager/get_state_manager.dart';
import 'package:get/route_manager.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

// 商品评价
class GoodsComment extends GetView<GoodsCommentController> {
  @override
  Widget build(BuildContext context) {
    Get.put(GoodsCommentController());

    return Scaffold(
      appBar: TopBar(
        title: '商品评价',
        isBack: true,
        brightness: Brightness.light,
      ),
      body: PullRefresh(
        refreshController: controller.refreshController,
        onRefresh: controller.onRefresh,
        onLoading: controller.onLoading,
        child: _buildComment(),
      ),
    );
  }

  // 评价
  _buildComment() {
    return ListView.builder(
      itemCount: controller.productList.length,
      itemBuilder: (BuildContext context, int index) {
        var item = controller.productList[index];
        return GestureDetector(
          onTap: () {},
          child: Container(
            margin: EdgeInsets.only(top: 10.h),
            padding: EdgeInsets.symmetric(vertical: 20.h, horizontal: 15.w),
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.circular(10.r),
            ),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  children: [
                    Container(
                      width: 40.r,
                      height: 40.r,
                      decoration: BoxDecoration(
                        color: Color(0xFFF5F5F5),
                        borderRadius: BorderRadius.circular(40.r),
                      ),
                      child: ClipRRect(
                        borderRadius: BorderRadius.circular(40.r),
                        child: Image.network(
                          item['avatar'],
                          fit: BoxFit.cover,
                        ),
                      ),
                    ),
                    Expanded(
                      child: Container(
                        margin: EdgeInsets.only(left: 12.w),
                        child: Text(
                          item['title'],
                          maxLines: 1,
                          style: TextStyle(
                            fontWeight: FontWeight.w500,
                            fontSize: 14.sp,
                          ),
                        ),
                      ),
                    ),
                    Container(
                      margin: EdgeInsets.only(left: 12.w),
                      child: Text(
                        item['date'],
                        style: TextStyle(
                          color: Color(0xFF888888),
                          fontSize: 11.w,
                        ),
                      ),
                    ),
                  ],
                ),
                Container(
                  margin: EdgeInsets.only(top: 8.h),
                  child: Text(
                    item['comment'],
                    style: TextStyle(
                      fontSize: 16.sp,
                      height: 1.5.h,
                    ),
                  ),
                ),
                Container(
                  margin: EdgeInsets.only(top: 8.h),
                  child: GridView(
                    padding: EdgeInsets.all(0),
                    shrinkWrap: true,
                    gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                      crossAxisCount: 3,
                      crossAxisSpacing: 6.w,
                      mainAxisSpacing: 6.w,
                      childAspectRatio: 1 / 1,
                    ),
                    physics: NeverScrollableScrollPhysics(),
                    children: List.generate(
                      item['children'].length,
                      (index) => GestureDetector(
                        onTap: () {
                          Get.to(
                            () => PictureView(
                              imgList: item['children'],
                              initialPage: index,
                              opacity: true,
                              onPageChanged: (index) {},
                            ),
                            transition: Transition.fadeIn,
                            fullscreenDialog: true,
                            duration: Duration(
                              milliseconds: 500,
                            ),
                            opaque: false,
                          );
                        },
                        child: Container(
                          decoration: BoxDecoration(
                            color: Color(0xFFF5F5F5),
                            borderRadius: BorderRadius.circular(5.r),
                          ),
                          child: ClipRRect(
                            borderRadius: BorderRadius.circular(5.r),
                            child: Stack(
                              fit: StackFit.expand,
                              children: [
                                Image.network(
                                  item['children'][index],
                                  fit: BoxFit.cover,
                                ),
                                Hero(
                                  transitionOnUserGestures: true,
                                  tag: item['children'][index],
                                  child: Image.network(
                                    item['children'][index],
                                    fit: BoxFit.cover,
                                  ),
                                ),
                              ],
                            ),
                          ),
                        ),
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ),
        );
      },
    );
  }
}
